import {
  Cell, Gene, Organ, P,
} from '@valuation/rules-engine'

import { MyLifeFactory } from './engine.ts'
import { getEditor } from './test'

/* const { doc } = editor.state; */
async function main() {
  const editor = await getEditor()

  const factory = new MyLifeFactory({
    a: () => ({ name: 'a', column: 'age', from: 'this' } satisfies Cell),
    b: () => ({ name: 'a', column: 'age', from: 'this' } satisfies Cell),
    c: Organ.create({
      name: 'c',
      description: 'a的年龄加b的年龄',
      gene: '_.sum([a,b,d])',
    }),
    d: Organ.create({
      name: 'd',
      description: 'a的年龄加b的年龄',
      gene: Gene.from(['a', 'b'], ({ a, b }: P) => a + b),
    }),
  })

  factory.initialize()
  const value = factory.create('c')// 返回a 的实例

  console.log(value)
  console.log(editor.doc)
}
main().then(() => {})
